#!/usr/bin/env bash

set -o nounset
set -o errexit
set -o pipefail

STARTUP_DIR="$( cd "$( dirname "$0" )" && pwd )"

source ${STARTUP_DIR}/../settings.sh
source ${STARTUP_DIR}/get-argocd-server-url

KUBECTL="kubectl --context=${KUBE_CONTEXT}"

ADMIN_PASSWORD=$(${KUBECTL} get pods -n argocd -l app.kubernetes.io/name=argocd-server -o name | cut -d'/' -f 2)

login="argocd login "$(getUrl)" --username admin --password ${ADMIN_PASSWORD}"

if [ -n "${KUBE_CONTEXT}" ]
then
  login+=" --name ${KUBE_CONTEXT}"
fi

echo ""
echo $login
echo ""

